//NXP PCA9635 library
//mbed Team     -   1st June 2011
//Ioannis Kedros
//updated by Daniel Worrall - 28th June 2011

#ifndef Bike_Display_I2C_Functions_H_
#define Bike_Display_I2C_Functions_H_

#include <plib.h>


UINT8 I2CData[30];
UINT8	LED_Driver_Chip;
UINT8	LED_Driver_Chip_Address;
UINT8	LED_Brightness;
I2C_7_BIT_ADDRESS	PCA9635Addr1;
I2C_7_BIT_ADDRESS	PCA9635Addr2;

// I2C Definitions
#define I2C_CLOCK_FREQ              100000

// LED Driver Constants
#define LED_DRIVER_I2C_BUS			I2C1
#define LED_DRIVER_ADDRESS_1        0x15        // 0b0010101 LED Driver address IC1
#define LED_DRIVER_ADDRESS_2        0x17        // 0b0010111 LED Driver address IC2
#define LED_DRIVER_ALL_ON	        0xE0        // 0b0010111 LED Driver address IC2
        
#define ALL 0xFF

/** Set a particular output on PCA9635 high
*
* @param led LED pin coordinates
*/
void PCA9635_LED_On(char led);

/** Reset a particular output on PCA9635 low
*
* @param led LED pin coordinates
*/
void PCA9635_LED_Off(char led);

/**Set all pins passed as argument high or low for current address
*
* @param leds Set output according to parameter value - e.g. 0x0003 >> p0 & p1 high, rest low
*/
//void bus(short leds);

/**Set all pins passed as argument high or low for specified address
*
* @param led Pin co-ordinates
* @param value Brightness value
*/
void PCA9635_Brightness(char led, char value);

/** Set write address
*
* &param address write address
*/
void PCA9635_Set_Address(UINT8 address);

/** Reset chip 
*
*/
void PCA9635_Reset(UINT8 address);
/** Initialise chip - MUST call this before calling any other functions
*
* @param address hardware address
*/
void PCA9635_Init(void);

int I2C_write(UINT8 address, UINT8 cmd[], int size); 

BOOL TransmitOneByte(UINT8 data);

#endif
